package jwebtest.AOP.proxy;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class AroundProxy1 implements MethodInterceptor {

	@SuppressWarnings("unchecked")
	public <T> T getProxy(Class<T> cls) {
		return (T) Enhancer.create(cls, this);
	}

	@Override
	public Object intercept(Object target, Method method, Object[] args, MethodProxy proxy) throws Throwable {
		doBefore();
		Object result = proxy.invokeSuper(target, args);
		doAfter();
		return result;
	}

	private void doBefore() {
		System.out.println("==Before");
	}

	private void doAfter() {
		System.out.println("==After");
	}

}
